home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gui / muibuilderv11.lha / muibuilder / mb / c / locale / Small_cat.c < prev    next >
C/C++ Source or Header  |  1994-03-06  |  7KB  |  229 lines

  1. /****************************************************************
  2.    This file was created automatically by `FlexCat V1.0'
  3.    Do NOT edit by hand!
  4. ****************************************************************/
  5.  
  6. #ifndef Small_Example_CAT_H
  7. #include "Small_Example_CAT.h"
  8. #endif    /*  !Small_Example_CAT_H         */
  9.  
  10. #include <string.h>
  11.  
  12. #ifndef EXEC_MEMORY_H
  13. #include <exec/memory.h>
  14. #endif    /*  !EXEC_MEMORY_H        */
  15. #ifndef LIBRARIES_IFFPARSE_H
  16. #include <libraries/iffparse.h>
  17. #endif    /*  !LIBRARIES_IFFPARSE_H   */
  18.  
  19. #ifndef CLIB_IFFPARSE_PROTOS_H
  20. #include <clib/iffparse_protos.h>
  21. #endif    /*  !CLIB_IFFPARSE_PROTOS_H */
  22. #ifndef CLIB_LOCALE_PROTOS_H
  23. #include <clib/locale_protos.h>
  24. #endif    /*  !CLIB_LOCALE_PROTOS_H   */
  25. #ifndef CLIB_DOS_PROTOS_H
  26. #include <clib/dos_protos.h>
  27. #endif    /*  !DOS_PROTOS_H        */
  28. #ifndef CLIB_EXEC_PROTOS_H
  29. #include <clib/exec_protos.h>
  30. #endif    /*  !EXEC_PROTOS_H        */
  31. #ifndef CLIB_UTILITY_PROTOS_H
  32. #include <clib/utility_protos.h>
  33. #endif    /*  !CLIB_UTILITY_PROTOS_H  */
  34.  
  35. #ifdef AZTEC_C
  36. #ifndef __PRAGMAS_LOCALE_LIB_H
  37. #include <pragmas/locale_lib.h>
  38. #endif    /*  !PRAGMAS_LOCALE_LIB_H   */
  39. #ifndef __PRAGMAS_IFFPARSE_LIB_H
  40. #include <pragmas/iffparse_lib.h>
  41. #endif    /*  !PRAGMAS_IFFPARSE_LIB_H */
  42. #ifndef __PRAGMAS_DOS_LIB_H
  43. #include <pragmas/dos_lib.h>
  44. #endif    /*  !PRAGMAS_DOS_LIB_H        */
  45. #ifndef __PRAGMAS_EXEC_LIB_H
  46. #include <pragmas/exec_lib.h>
  47. #endif    /*  !PRAGMAS_EXEC_LIB_H     */
  48. #ifndef __PRAGMAS_UTILITY_LIB_H
  49. #include <pragmas/utility_lib.h>
  50. #endif    /*  !PRAGMAS_UTILITY_LIB_H  */
  51. #endif    /*  AZTEC_C            */
  52.  
  53. static LONG Small_Example_Version = 0;
  54. static const STRPTR Small_Example_BuiltInLanguage = (STRPTR) "english";
  55.  
  56. struct FC_Type
  57. {   LONG    ID;
  58.     STRPTR  Str;
  59. };
  60.  
  61. static const struct FC_Type Small_Example_Array [] =
  62. {
  63.     MSG_AppDescription, (STRPTR) "Here is a small Example of MUI-Builder",
  64.     MSG_WI_smallExample, (STRPTR) "Small Example",
  65.     MSG_GR_lists, (STRPTR) "two lists",
  66.     MSG_BT_ok, (STRPTR) "_o OK",
  67.     MSG_BT_cancel, (STRPTR) "_c Cancel",
  68. };
  69.  
  70. static struct Catalog *Small_Example_Catalog = NULL;
  71. static struct FC_Type *Small_Example_OwnCatalog = NULL;
  72. static LONG Small_Example_OwnStrings;
  73. static LONG Small_Example_OwnBytes;
  74.  
  75. void OpenSmall_ExampleCatalog(struct Locale *loc, STRPTR language)
  76. { LONG tag, tagarg;
  77.   extern struct Library *LocaleBase;
  78.   extern struct Library *IFFParseBase;
  79.  
  80.   CloseSmall_ExampleCatalog();  /*  Not needed if the programmer pairs Open-()
  81.              and CloseCatalog() right, but does no harm. */
  82.   if (language == NULL)
  83.   { tag = TAG_IGNORE;
  84.   }
  85.   else
  86.   { tag = OC_Language;
  87.     tagarg = (LONG) language;
  88.   }
  89.   if (LocaleBase != NULL  &&  Small_Example_Catalog == NULL)
  90.   { Small_Example_Catalog = OpenCatalog(loc, (STRPTR) "Small_Example.catalog",
  91.                  OC_BuiltInLanguage, Small_Example_BuiltInLanguage,
  92.                  tag, tagarg,
  93.                  OC_Version, Small_Example_Version,
  94.                  TAG_DONE);
  95.   }
  96.   if (LocaleBase == NULL  &&  IFFParseBase != NULL  &&  language != NULL  &&
  97.       Stricmp(language, Small_Example_BuiltInLanguage) != 0)
  98.   { struct IFFHandle *iffhandle;
  99.     char path[128]; /*    Enough to hold 4 path items (dos.library 3.0)  */
  100.  
  101.     if ((iffhandle = AllocIFF())  !=  NULL)
  102.     { /*  Trying to open the catalog  */
  103.       strcpy(path, "Catalogs");
  104.       AddPart((STRPTR) path, language, sizeof(path));
  105.       AddPart((STRPTR) path, (STRPTR) "Small_Example.catalog", sizeof(path));
  106.       if ((iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))
  107.                  ==  NULL)
  108.       { strcpy(path, "Locale:Catalogs");
  109.     AddPart((STRPTR) path, language, sizeof(path));
  110.     AddPart((STRPTR) path, (STRPTR) "Small_Example.catalog", sizeof(path));
  111.     iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
  112.       }
  113.  
  114.       if (iffhandle->iff_Stream)
  115.       { InitIFFasDOS(iffhandle);
  116.     if (!OpenIFF(iffhandle, IFFF_READ))
  117.     { if (!PropChunk(iffhandle, MAKE_ID('C','T','L','G'),
  118.              MAKE_ID('S','T','R','S')))
  119.       { struct StoredProperty *sp;
  120.         int error;
  121.  
  122.         for (;;)
  123.         { if ((error = ParseIFF(iffhandle, IFFPARSE_STEP))
  124.              ==  IFFERR_EOC)
  125.           { continue;
  126.           }
  127.           if (error != 0)
  128.           { break;
  129.           }
  130.  
  131.           if (sp = FindProp(iffhandle, MAKE_ID('C','T','L','G'),
  132.                 MAKE_ID('S','T','R','S')))
  133.           { LONG *ptr;
  134.         LONG BytesToScan, StrLength;
  135.  
  136.         /*  First scan: Check the number of strings        */
  137.         /*  Note that this assumes that the strings are padded    */
  138.         /*  to a longword boundary!                */
  139.         Small_Example_OwnBytes = 0;
  140.         Small_Example_OwnStrings = 0;
  141.         BytesToScan = sp->sp_Size;
  142.         ptr = sp->sp_Data;
  143.         while (BytesToScan > 0)
  144.         { ++Small_Example_OwnStrings;
  145.           ++ptr;              /*  Skip ID        */
  146.           StrLength = *ptr+1;          /*  NUL-Byte!        */
  147.           Small_Example_OwnBytes += StrLength;
  148.           ptr += 1+(StrLength+3)/4;   /*  Skip Length and String*/
  149.           BytesToScan -= 8+((StrLength+3)/4)*4;
  150.         }
  151.  
  152.         /*  Marginal check: BytesToScan has to be 0!        */
  153.         if (BytesToScan == 0)
  154.         { char *cptr;
  155.           LONG i;
  156.  
  157.           if (Small_Example_OwnCatalog = (struct FC_Type *)
  158.               AllocMem(Small_Example_OwnStrings*sizeof(struct FC_Type)+Small_Example_OwnBytes,
  159.                    MEMF_ANY))
  160.           { /*    Second scan: Copy the strings and their ID's    */
  161.             cptr = (char *) &Small_Example_OwnCatalog[Small_Example_OwnStrings];
  162.             BytesToScan = sp->sp_Size;
  163.             ptr = sp->sp_Data;
  164.             i = 0;
  165.             while (BytesToScan > 0)
  166.             { Small_Example_OwnCatalog[i].ID = *(ptr++);
  167.               Small_Example_OwnCatalog[i].Str = (STRPTR) cptr;
  168.               StrLength = *ptr+1;     /*  NUL-Byte!        */
  169.               ptr++;
  170.               strncpy(cptr, (char *) ptr, StrLength);
  171.                     /*  Not more, not less bytes!    */
  172.               cptr+=StrLength;
  173.               ptr += (StrLength+3)/4;
  174.               BytesToScan -= 8+((StrLength+3)/4)*4;
  175.               ++i;
  176.             }
  177.             break;
  178.           }
  179.         }
  180.           }
  181.         }
  182.       }
  183.       CloseIFF(iffhandle);
  184.     }
  185.     Close(iffhandle->iff_Stream);
  186.       }
  187.  
  188.       FreeIFF(iffhandle);
  189.     }
  190.   }
  191. }
  192.  
  193.  
  194. void CloseSmall_ExampleCatalog(void)
  195. { if (LocaleBase != NULL)
  196.   { CloseCatalog(Small_Example_Catalog);
  197.   }
  198.   Small_Example_Catalog = NULL;
  199.   if (Small_Example_OwnCatalog != NULL)
  200.   { FreeMem(Small_Example_OwnCatalog,
  201.         Small_Example_OwnStrings*sizeof(struct FC_Type)+Small_Example_OwnBytes);
  202.     Small_Example_OwnCatalog = NULL;
  203.   }
  204. }
  205.  
  206.  
  207. STRPTR GetSmall_ExampleString(LONG strnum)
  208. { STRPTR defaultstr = NULL;
  209.   LONG i;
  210.  
  211.   for (i = 0;  i < sizeof(Small_Example_Array)/sizeof(struct FC_Type);  i++)
  212.     { if (Small_Example_Array[i].ID == strnum)
  213.       { defaultstr = Small_Example_Array[i].Str;
  214.     break;
  215.       }
  216.     }
  217.   if (Small_Example_Catalog == NULL)
  218.   { if (Small_Example_OwnCatalog != NULL)
  219.     { for (i = 0;  i < Small_Example_OwnStrings;  i++)
  220.        { if (Small_Example_OwnCatalog[i].ID == strnum)
  221.      { return(Small_Example_OwnCatalog[i].Str);
  222.      }
  223.        }
  224.     }
  225.     return(defaultstr);
  226.   }
  227.   return(GetCatalogStr(Small_Example_Catalog, strnum, defaultstr));
  228. }
  229.